package com.global.variable.common.web.utils;

import org.springframework.web.util.HtmlUtils;

import java.beans.PropertyEditorSupport;

/**
 * company 重庆庆云石油工程技术有限责任公司
 * FileName StringEscapeEditor
 * Package com.basic.management.logic.util
 * Description 防止xss攻击
 * author Administrator
 * create 2018-10-17 下午 2:14
 * version V1.0
 */
public class StringEscapeEditor extends PropertyEditorSupport {

    public StringEscapeEditor() {
    }

    @Override
    public String getAsText() {
        Object value = getValue();
        return value != null ? value.toString() : "";
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (text == null) {
            setValue(null);
        } else {
            setValue(HtmlUtils.htmlEscape(text));
        }
    }
}
